﻿<%@ page contentType="text/html; charset=utf-8" %>
<%@ page language="java" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%@ page import="java.sql.*" %>
<%

 Object uname=session.getAttribute("uname");
 String newEmail=request.getParameter("newE");

//数据库用户名
String userName="root";
//密码
String userPasswd="";
//数据库名
String dbName="a0713225307";

try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
String u ="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd+"&useUnicode=true&characterEncoding=UTF-8";
  
java.sql.Connection con = java.sql.DriverManager.getConnection(u,"root","");
//java.sql.Statement statement=con.createStatement();
String sql="update users set email='"+newEmail+"' where uName='"+uname+"'";

 Statement statement=con.createStatement(); 
 
   if(statement.executeUpdate(sql)==1){
    System.out.println("success");
	
	response.sendRedirect("user.jsp");
	
     }else{
    out.print("fail");
     }
     
       if(statement!=null){
  statement.close();
  }
  if(con!=null){
  con.close();
  }
  }catch(Exception e){
   e.printStackTrace();
   System.out.println(e);
  } 

%>